home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 1999 #5 / 1999 CD 5 (black).iso / Delphi3 / install / data.z / SYSUTILS.INT < prev    next >
Encoding:
Text File  |  1997-08-05  |  77.8 KB  |  1,930 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Runtime Library                          }
  5. {       System Utilities Unit                           }
  6. {                                                       }
  7. {       Copyright (C) 1995,97 Borland International     }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit SysUtils;
  12.  
  13. {$H+}
  14.  
  15. interface
  16.  
  17. uses Windows;
  18.  
  19. const
  20.  
  21. { File open modes }
  22.  
  23.   fmOpenRead       = $0000;
  24.   fmOpenWrite      = $0001;
  25.   fmOpenReadWrite  = $0002;
  26.   fmShareCompat    = $0000;
  27.   fmShareExclusive = $0010;
  28.   fmShareDenyWrite = $0020;
  29.   fmShareDenyRead  = $0030;
  30.   fmShareDenyNone  = $0040;
  31.  
  32. { File attribute constants }
  33.  
  34.   faReadOnly  = $00000001;
  35.   faHidden    = $00000002;
  36.   faSysFile   = $00000004;
  37.   faVolumeID  = $00000008;
  38.   faDirectory = $00000010;
  39.   faArchive   = $00000020;
  40.   faAnyFile   = $0000003F;
  41.  
  42. { File mode magic numbers }
  43.  
  44.   fmClosed = $D7B0;
  45.   fmInput  = $D7B1;
  46.   fmOutput = $D7B2;
  47.   fmInOut  = $D7B3;
  48.  
  49. { Seconds and milliseconds per day }
  50.  
  51.   SecsPerDay = 24 * 60 * 60;
  52.   MSecsPerDay = SecsPerDay * 1000;
  53.  
  54. { Days between 1/1/0001 and 12/31/1899 }
  55.  
  56.   DateDelta = 693594;
  57.  
  58. type
  59.  
  60. { Type conversion records }
  61.  
  62.   WordRec = packed record
  63.     Lo, Hi: Byte;
  64.   end;
  65.  
  66.   LongRec = packed record
  67.     Lo, Hi: Word;
  68.   end;
  69.  
  70.   TMethod = record
  71.     Code, Data: Pointer;
  72.   end;
  73.  
  74. { General arrays }
  75.  
  76.   PByteArray = ^TByteArray;
  77.   TByteArray = array[0..32767] of Byte;
  78.  
  79.   PWordArray = ^TWordArray;
  80.   TWordArray = array[0..16383] of Word;
  81.  
  82. { Generic procedure pointer }
  83.  
  84.   TProcedure = procedure;
  85.  
  86. { Generic filename type }
  87.  
  88.   TFileName = string;
  89.  
  90. { Search record used by FindFirst, FindNext, and FindClose }
  91.  
  92.   TSearchRec = record
  93.     Time: Integer;
  94.     Size: Integer;
  95.     Attr: Integer;
  96.     Name: TFileName;
  97.     ExcludeAttr: Integer;
  98.     FindHandle: THandle;
  99.     FindData: TWin32FindData;
  100.   end;
  101.  
  102. { Typed-file and untyped-file record }
  103.  
  104.   TFileRec = record
  105.     Handle: Integer;
  106.     Mode: Integer;
  107.     RecSize: Cardinal;
  108.     Private: array[1..28] of Byte;
  109.     UserData: array[1..32] of Byte;
  110.     Name: array[0..259] of Char;
  111.   end;
  112.  
  113. { Text file record structure used for Text files }
  114.  
  115.   PTextBuf = ^TTextBuf;
  116.   TTextBuf = array[0..127] of Char;
  117.   TTextRec = record
  118.     Handle: Integer;
  119.     Mode: Integer;
  120.     BufSize: Cardinal;
  121.     BufPos: Cardinal;
  122.     BufEnd: Cardinal;
  123.     BufPtr: PChar;
  124.     OpenFunc: Pointer;
  125.     InOutFunc: Pointer;
  126.     FlushFunc: Pointer;
  127.     CloseFunc: Pointer;
  128.     UserData: array[1..32] of Byte;
  129.     Name: array[0..259] of Char;
  130.     Buffer: TTextBuf;
  131.   end;
  132.  
  133. { FloatToText, FloatToTextFmt, TextToFloat, and FloatToDecimal type codes }
  134.  
  135.   TFloatValue = (fvExtended, fvCurrency);
  136.  
  137. { FloatToText format codes }
  138.  
  139.   TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
  140.  
  141. { FloatToDecimal result record }
  142.  
  143.   TFloatRec = packed record
  144.     Exponent: Smallint;
  145.     Negative: Boolean;
  146.     Digits: array[0..20] of Char;
  147.   end;
  148.  
  149. { Date and time record }
  150.  
  151.   TTimeStamp = record
  152.     Time: Integer;      { Number of milliseconds since midnight }
  153.     Date: Integer;      { One plus number of days since 1/1/0001 }
  154.   end;
  155.  
  156. { MultiByte Character Set (MBCS) byte type }
  157.   TMbcsByteType = (mbSingleByte, mbLeadByte, mbTrailByte);
  158.  
  159. { System Locale information record }
  160.   TSysLocale = packed record
  161.     DefaultLCID: LCID;
  162.     PriLangID: LANGID;
  163.     SubLangID: LANGID;
  164.     FarEast: Boolean;
  165.   end;
  166.  
  167. { Exceptions }
  168.  
  169.   Exception = class(TObject)
  170.   public
  171.     constructor Create(const Msg: string);
  172.     constructor CreateFmt(const Msg: string; const Args: array of const);
  173.     constructor CreateRes(Ident: Integer);
  174.     constructor CreateResFmt(Ident: Integer; const Args: array of const);
  175.     constructor CreateHelp(const Msg: string; AHelpContext: Integer);
  176.     constructor CreateFmtHelp(const Msg: string; const Args: array of const;
  177.       AHelpContext: Integer);
  178.     constructor CreateResHelp(Ident: Integer; AHelpContext: Integer);
  179.     constructor CreateResFmtHelp(Ident: Integer; const Args: array of const;
  180.       AHelpContext: Integer);
  181.     property HelpContext: Integer;
  182.     property Message: string;
  183.   end;
  184.  
  185.   ExceptClass = class of Exception;
  186.  
  187.   EAbort = class(Exception);
  188.  
  189.   EOutOfMemory = class(Exception)
  190.   public
  191.     destructor Destroy; override;
  192.     procedure FreeInstance; override;
  193.   end;
  194.  
  195.   EInOutError = class(Exception)
  196.   public
  197.     ErrorCode: Integer;
  198.   end;
  199.  
  200.   EIntError = class(Exception);
  201.   EDivByZero = class(EIntError);
  202.   ERangeError = class(EIntError);
  203.   EIntOverflow = class(EIntError);
  204.  
  205.   EMathError = class(Exception);
  206.   EInvalidOp = class(EMathError);
  207.   EZeroDivide = class(EMathError);
  208.   EOverflow = class(EMathError);
  209.   EUnderflow = class(EMathError);
  210.  
  211.   EInvalidPointer = class(Exception);
  212.  
  213.   EInvalidCast = class(Exception);
  214.  
  215.   EConvertError = class(Exception);
  216.  
  217.   EAccessViolation = class(Exception);
  218.   EPrivilege = class(Exception);
  219.   EStackOverflow = class(Exception);
  220.   EControlC = class(Exception);
  221.  
  222.   EVariantError = class(Exception);
  223.  
  224.   EPropReadOnly = class(Exception);
  225.   EPropWriteOnly = class(Exception);
  226.  
  227.   EExternalException = class(Exception)
  228.   public
  229.     ExceptionRecord: PExceptionRecord;
  230.   end;
  231.  
  232.   EAssertionFailed = class(Exception);
  233.  
  234.   EAbstractError = class(Exception);
  235.  
  236.   EIntfCastError = class(Exception);
  237.  
  238.   EInvalidContainer = class(Exception);
  239.   EInvalidInsert = class(Exception);
  240.  
  241.   EPackageError = class(Exception);
  242.  
  243.   EWin32Error = class(Exception)
  244.   public
  245.     ErrorCode: DWORD;
  246.   end;
  247.  
  248. var
  249.  
  250. { Empty string and null string pointer. These constants are provided for
  251.   backwards compatibility only.  }
  252.  
  253.   EmptyStr: string = '';
  254.   NullStr: PString = @EmptyStr;
  255.  
  256. { Win32 platform identifier.  This will be one of the following values:
  257.  
  258.     VER_PLATFORM_WIN32s
  259.     VER_PLATFORM_WIN32_WINDOWS
  260.     VER_PLATFORM_WIN32_NT
  261.  
  262.   See WINDOWS.PAS for the numerical values. }
  263.  
  264.   Win32Platform: Integer = 0;
  265.  
  266. { Win32 OS version information -
  267.  
  268.   see TOSVersionInfo.dwMajorVersion/dwMinorVersion/dwBuildNumber }
  269.  
  270.   Win32MajorVersion: Integer = 0;
  271.   Win32MinorVersion: Integer = 0;
  272.   Win32BuildNumber: Integer = 0;
  273.  
  274. { Win32 OS extra version info string -
  275.  
  276.   see TOSVersionInfo.szCSDVersion }
  277.  
  278.   Win32CSDVersion: string = '';
  279.  
  280. { Currency and date/time formatting options
  281.  
  282.   The initial values of these variables are fetched from the system registry
  283.   using the GetLocaleInfo function in the Win32 API. The description of each
  284.   variable specifies the LOCALE_XXXX constant used to fetch the initial
  285.   value.
  286.  
  287.   CurrencyString - Defines the currency symbol used in floating-point to
  288.   decimal conversions. The initial value is fetched from LOCALE_SCURRENCY.
  289.  
  290.   CurrencyFormat - Defines the currency symbol placement and separation
  291.   used in floating-point to decimal conversions. Possible values are:
  292.  
  293.     0 = '$1'
  294.     1 = '1$'
  295.     2 = '$ 1'
  296.     3 = '1 $'
  297.  
  298.   The initial value is fetched from LOCALE_ICURRENCY.
  299.  
  300.   NegCurrFormat - Defines the currency format for used in floating-point to
  301.   decimal conversions of negative numbers. Possible values are:
  302.  
  303.     0 = '($1)'      4 = '(1$)'      8 = '-1 $'      12 = '$ -1'
  304.     1 = '-$1'       5 = '-1$'       9 = '-$ 1'      13 = '1- $'
  305.     2 = '$-1'       6 = '1-$'      10 = '1 $-'      14 = '($ 1)'
  306.     3 = '$1-'       7 = '1$-'      11 = '$ 1-'      15 = '(1 $)'
  307.  
  308.   The initial value is fetched from LOCALE_INEGCURR.
  309.  
  310.   ThousandSeparator - The character used to separate thousands in numbers
  311.   with more than three digits to the left of the decimal separator. The
  312.   initial value is fetched from LOCALE_STHOUSAND.
  313.  
  314.   DecimalSeparator - The character used to separate the integer part from
  315.   the fractional part of a number. The initial value is fetched from
  316.   LOCALE_SDECIMAL.
  317.  
  318.   CurrencyDecimals - The number of digits to the right of the decimal point
  319.   in a currency amount. The initial value is fetched from LOCALE_ICURRDIGITS.
  320.  
  321.   DateSeparator - The character used to separate the year, month, and day
  322.   parts of a date value. The initial value is fetched from LOCATE_SDATE.
  323.  
  324.   ShortDateFormat - The format string used to convert a date value to a
  325.   short string suitable for editing. For a complete description of date and
  326.   time format strings, refer to the documentation for the FormatDate
  327.   function. The short date format should only use the date separator
  328.   character and the  m, mm, d, dd, yy, and yyyy format specifiers. The
  329.   initial value is fetched from LOCALE_SSHORTDATE.
  330.  
  331.   LongDateFormat - The format string used to convert a date value to a long
  332.   string suitable for display but not for editing. For a complete description
  333.   of date and time format strings, refer to the documentation for the
  334.   FormatDate function. The initial value is fetched from LOCALE_SLONGDATE.
  335.  
  336.   TimeSeparator - The character used to separate the hour, minute, and
  337.   second parts of a time value. The initial value is fetched from
  338.   LOCALE_STIME.
  339.  
  340.   TimeAMString - The suffix string used for time values between 00:00 and
  341.   11:59 in 12-hour clock format. The initial value is fetched from
  342.   LOCALE_S1159.
  343.  
  344.   TimePMString - The suffix string used for time values between 12:00 and
  345.   23:59 in 12-hour clock format. The initial value is fetched from
  346.   LOCALE_S2359.
  347.  
  348.   ShortTimeFormat - The format string used to convert a time value to a
  349.   short string with only hours and minutes. The default value is computed
  350.   from LOCALE_ITIME and LOCALE_ITLZERO.
  351.  
  352.   LongTimeFormat - The format string used to convert a time value to a long
  353.   string with hours, minutes, and seconds. The default value is computed
  354.   from LOCALE_ITIME and LOCALE_ITLZERO.
  355.  
  356.   ShortMonthNames - Array of strings containing short month names. The mmm
  357.   format specifier in a format string passed to FormatDate causes a short
  358.   month name to be substituted. The default values are fecthed from the
  359.   LOCALE_SABBREVMONTHNAME system locale entries.
  360.  
  361.   LongMonthNames - Array of strings containing long month names. The mmmm
  362.   format specifier in a format string passed to FormatDate causes a long
  363.   month name to be substituted. The default values are fecthed from the
  364.   LOCALE_SMONTHNAME system locale entries.
  365.  
  366.   ShortDayNames - Array of strings containing short day names. The ddd
  367.   format specifier in a format string passed to FormatDate causes a short
  368.   day name to be substituted. The default values are fecthed from the
  369.   LOCALE_SABBREVDAYNAME system locale entries.
  370.  
  371.   LongDayNames - Array of strings containing long day names. The dddd
  372.   format specifier in a format string passed to FormatDate causes a long
  373.   day name to be substituted. The default values are fecthed from the
  374.   LOCALE_SDAYNAME system locale entries. }
  375.  
  376. var
  377.   CurrencyString: string;
  378.   CurrencyFormat: Byte;
  379.   NegCurrFormat: Byte;
  380.   ThousandSeparator: Char;
  381.   DecimalSeparator: Char;
  382.   CurrencyDecimals: Byte;
  383.   DateSeparator: Char;
  384.   ShortDateFormat: string;
  385.   LongDateFormat: string;
  386.   TimeSeparator: Char;
  387.   TimeAMString: string;
  388.   TimePMString: string;
  389.   ShortTimeFormat: string;
  390.   LongTimeFormat: string;
  391.   ShortMonthNames: array[1..12] of string;
  392.   LongMonthNames: array[1..12] of string;
  393.   ShortDayNames: array[1..7] of string;
  394.   LongDayNames: array[1..7] of string;
  395.   SysLocale: TSysLocale;
  396.   EraNames: array[1..7] of string;
  397.   EraYearOffsets: array[1..7] of Integer;
  398.  
  399. { Memory management routines }
  400.  
  401. { AllocMem allocates a block of the given size on the heap. Each byte in
  402.   the allocated buffer is set to zero. To dispose the buffer, use the
  403.   FreeMem standard procedure. }
  404.  
  405. function AllocMem(Size: Cardinal): Pointer;
  406.  
  407. { Exit procedure handling }
  408.  
  409. { AddExitProc adds the given procedure to the run-time library's exit
  410.   procedure list. When an application terminates, its exit procedures are
  411.   executed in reverse order of definition, i.e. the last procedure passed
  412.   to AddExitProc is the first one to get executed upon termination. }
  413.  
  414. procedure AddExitProc(Proc: TProcedure);
  415.  
  416. { String handling routines }
  417.  
  418. { NewStr allocates a string on the heap. NewStr is provided for backwards
  419.   compatibility only. }
  420.  
  421. function NewStr(const S: string): PString;
  422.  
  423. { DisposeStr disposes a string pointer that was previously allocated using
  424.   NewStr. DisposeStr is provided for backwards compatibility only. }
  425.  
  426. procedure DisposeStr(P: PString);
  427.  
  428. { AssignStr assigns a new dynamically allocated string to the given string
  429.   pointer. AssignStr is provided for backwards compatibility only. }
  430.  
  431. procedure AssignStr(var P: PString; const S: string);
  432.  
  433. { AppendStr appends S to the end of Dest. AppendStr is provided for
  434.   backwards compatibility only. Use "Dest := Dest + S" instead. }
  435.  
  436. procedure AppendStr(var Dest: string; const S: string);
  437.  
  438. { UpperCase converts all ASCII characters in the given string to upper case.
  439.   The conversion affects only 7-bit ASCII characters between 'a' and 'z'. To
  440.   convert 8-bit international characters, use AnsiUpperCase. }
  441.  
  442. function UpperCase(const S: string): string;
  443.  
  444. { LowerCase converts all ASCII characters in the given string to lower case.
  445.   The conversion affects only 7-bit ASCII characters between 'A' and 'Z'. To
  446.   convert 8-bit international characters, use AnsiLowerCase. }
  447.  
  448. function LowerCase(const S: string): string;
  449.  
  450. { CompareStr compares S1 to S2, with case-sensitivity. The return value is
  451.   less than 0 if S1 < S2, 0 if S1 = S2, or greater than 0 if S1 > S2. The
  452.   compare operation is based on the 8-bit ordinal value of each character
  453.   and is not affected by the current Windows locale. }
  454.  
  455. function CompareStr(const S1, S2: string): Integer;
  456.  
  457. { CompareMem performs a binary compare of Length bytes of memory referenced
  458.   by P1 to that of P2.  CompareMem returns True if the memory referenced by
  459.   P1 is identical to that of P2. }
  460.  
  461. function CompareMem(P1, P2: Pointer; Length: Integer): Boolean; assembler;
  462.  
  463. { CompareText compares S1 to S2, without case-sensitivity. The return value
  464.   is the same as for CompareStr. The compare operation is based on the 8-bit
  465.   ordinal value of each character, after converting 'a'..'z' to 'A'..'Z',
  466.   and is not affected by the current Windows locale. }
  467.  
  468. function CompareText(const S1, S2: string): Integer;
  469.  
  470. { AnsiUpperCase converts all characters in the given string to upper case.
  471.   The conversion uses the current Windows locale. }
  472.  
  473. function AnsiUpperCase(const S: string): string;
  474.  
  475. { AnsiLowerCase converts all characters in the given string to lower case.
  476.   The conversion uses the current Windows locale. }
  477.  
  478. function AnsiLowerCase(const S: string): string;
  479.  
  480. { AnsiCompareStr compares S1 to S2, with case-sensitivity. The compare
  481.   operation is controlled by the current Windows locale. The return value
  482.   is the same as for CompareStr. }
  483.  
  484. function AnsiCompareStr(const S1, S2: string): Integer;
  485.  
  486. { AnsiCompareText compares S1 to S2, without case-sensitivity. The compare
  487.   operation is controlled by the current Windows locale. The return value
  488.   is the same as for CompareStr. }
  489.  
  490. function AnsiCompareText(const S1, S2: string): Integer;
  491.  
  492. { AnsiStrComp compares S1 to S2, with case-sensitivity. The compare
  493.   operation is controlled by the current Windows locale. The return value
  494.   is the same as for CompareStr. }
  495.  
  496. function AnsiStrComp(S1, S2: PChar): Integer;
  497.  
  498. { AnsiStrIComp compares S1 to S2, without case-sensitivity. The compare
  499.   operation is controlled by the current Windows locale. The return value
  500.   is the same as for CompareStr. }
  501.  
  502. function AnsiStrIComp(S1, S2: PChar): Integer;
  503.  
  504. { AnsiStrLComp compares S1 to S2, with case-sensitivity, up to a maximum
  505.   length of MaxLen bytes. The compare operation is controlled by the
  506.   current Windows locale. The return value is the same as for CompareStr. }
  507.  
  508. function AnsiStrLComp(S1, S2: PChar; MaxLen: Cardinal): Integer;
  509.  
  510. { AnsiStrLIComp compares S1 to S2, without case-sensitivity, up to a maximum
  511.   length of MaxLen bytes. The compare operation is controlled by the
  512.   current Windows locale. The return value is the same as for CompareStr. }
  513.  
  514. function AnsiStrLIComp(S1, S2: PChar; MaxLen: Cardinal): Integer;
  515.  
  516. { AnsiStrLower converts all characters in the given string to lower case.
  517.   The conversion uses the current Windows locale. }
  518.  
  519. function AnsiStrLower(Str: PChar): PChar;
  520.  
  521. { AnsiStrUpper converts all characters in the given string to upper case.
  522.   The conversion uses the current Windows locale. }
  523.  
  524. function AnsiStrUpper(Str: PChar): PChar;
  525.  
  526. { AnsiLastChar returns a pointer to the last full character in the string.
  527.   This function supports multibyte characters  }
  528.  
  529. function AnsiLastChar(const S: string): PChar;
  530.  
  531. { AnsiStrLastChar returns a pointer to the last full character in the string.
  532.   This function supports multibyte characters.  }
  533.  
  534. function AnsiStrLastChar(P: PChar): PChar;
  535.  
  536. { Trim trims leading and trailing spaces and control characters from the
  537.   given string. }
  538.  
  539. function Trim(const S: string): string;
  540.  
  541. { TrimLeft trims leading spaces and control characters from the given
  542.   string. }
  543.  
  544. function TrimLeft(const S: string): string;
  545.  
  546. { TrimRight trims trailing spaces and control characters from the given
  547.   string. }
  548.  
  549. function TrimRight(const S: string): string;
  550.  
  551. { QuotedStr returns the given string as a quoted string. A single quote
  552.   character is inserted at the beginning and the end of the string, and
  553.   for each single quote character in the string, another one is added. }
  554.  
  555. function QuotedStr(const S: string): string;
  556.  
  557. { AnsiQuotedStr returns the given string as a quoted string, using the
  558.   provided Quote character.  A Quote character is inserted at the beginning
  559.   and end of thestring, and each Quote character in the string is doubled.
  560.   This function supports multibyte character strings (MBCS). }
  561.  
  562. function AnsiQuotedStr(const S: string; Quote: Char): string;
  563.  
  564. { AnsiExtractQuotedStr removes the Quote characters from the beginning and end
  565.   of a quoted string, and reduces pairs of Quote characters within the quoted
  566.   string to a single character. If the first character in Src is not the Quote
  567.   character, the function returns an empty string.  The function copies
  568.   characters from the Src to the result string until the second solitary
  569.   Quote character or the first null character in Src. The Src parameter is
  570.   updated to point to the first character following the quoted string.  If
  571.   the Src string does not contain a matching end Quote character, the Src
  572.   parameter is updated to point to the terminating null character in Src.
  573.   This function supports multibyte character strings (MBCS).  }
  574.  
  575. function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
  576.  
  577. { AdjustLineBreaks adjusts all line breaks in the given string to be true
  578.   CR/LF sequences. The function changes any CR characters not followed by
  579.   a LF and any LF characters not preceded by a CR into CR/LF pairs. }
  580.  
  581. function AdjustLineBreaks(const S: string): string;
  582.  
  583. { IsValidIdent returns true if the given string is a valid identifier. An
  584.   identifier is defined as a character from the set ['A'..'Z', 'a'..'z', '_']
  585.   followed by zero or more characters from the set ['A'..'Z', 'a'..'z',
  586.   '0..'9', '_']. }
  587.  
  588. function IsValidIdent(const Ident: string): Boolean;
  589.  
  590. { IntToStr converts the given value to its decimal string representation. }
  591.  
  592. function IntToStr(Value: Integer): string;
  593.  
  594. { IntToHex converts the given value to a hexadecimal string representation
  595.   with the minimum number of digits specified. }
  596.  
  597. function IntToHex(Value: Integer; Digits: Integer): string;
  598.  
  599. { StrToInt converts the given string to an integer value. If the string
  600.   doesn't contain a valid value, an EConvertError exception is raised. }
  601.  
  602. function StrToInt(const S: string): Integer;
  603.  
  604. { StrToIntDef converts the given string to an integer value. If the string
  605.   doesn't contain a valid value, the value given by Default is returned. }
  606.  
  607. function StrToIntDef(const S: string; Default: Integer): Integer;
  608.  
  609. { LoadStr loads the string resource given by Ident from the application's
  610.   executable file. If the string resource does not exist, an empty string
  611.   is returned. }
  612.  
  613. function LoadStr(Ident: Integer): string;
  614.  
  615. { LoadStr loads the string resource given by Ident from the application's
  616.   executable file, and uses it as the format string in a call to the
  617.   Format function with the given arguments. }
  618.  
  619. function FmtLoadStr(Ident: Integer; const Args: array of const): string;
  620.  
  621. { File management routines }
  622.  
  623. { FileOpen opens the specified file using the specified access mode. The
  624.   access mode value is constructed by OR-ing one of the fmOpenXXXX constants
  625.   with one of the fmShareXXXX constants. If the return value is positive,
  626.   the function was successful and the value is the file handle of the opened
  627.   file. A return value of -1 indicates that an error occurred. }
  628.  
  629. function FileOpen(const FileName: string; Mode: Integer): Integer;
  630.  
  631. { FileCreate creates a new file by the specified name. If the return value
  632.   is positive, the function was successful and the value is the file handle
  633.   of the new file. A return value of -1 indicates that an error occurred. }
  634.  
  635. function FileCreate(const FileName: string): Integer;
  636.  
  637. { FileRead reads Count bytes from the file given by Handle into the buffer
  638.   specified by Buffer. The return value is the number of bytes actually
  639.   read; it is less than Count if the end of the file was reached. The return
  640.   value is -1 if an error occurred. }
  641.  
  642. function FileRead(Handle: Integer; var Buffer; Count: Integer): Integer;
  643.  
  644. { FileWrite writes Count bytes to the file given by Handle from the buffer
  645.   specified by Buffer. The return value is the number of bytes actually
  646.   written, or -1 if an error occurred. }
  647.  
  648. function FileWrite(Handle: Integer; const Buffer; Count: Integer): Integer;
  649.  
  650. { FileSeek changes the current position of the file given by Handle to be
  651.   Offset bytes relative to the point given by Origin. Origin = 0 means that
  652.   Offset is relative to the beginning of the file, Origin = 1 means that
  653.   Offset is relative to the current position, and Origin = 2 means that
  654.   Offset is relative to the end of the file. The return value is the new
  655.   current position, relative to the beginning of the file, or -1 if an error
  656.   occurred. }
  657.  
  658. function FileSeek(Handle, Offset, Origin: Integer): Integer;
  659.  
  660. { FileClose closes the specified file. }
  661.  
  662. procedure FileClose(Handle: Integer);
  663.  
  664. { FileAge returns the date-and-time stamp of the specified file. The return
  665.   value can be converted to a TDateTime value using the FileDateToDateTime
  666.   function. The return value is -1 if the file does not exist. }
  667.  
  668. function FileAge(const FileName: string): Integer;
  669.  
  670. { FileExists returns a boolean value that indicates whether the specified
  671.   file exists. }
  672.  
  673. function FileExists(const FileName: string): Boolean;
  674.  
  675. { FindFirst searches the directory given by Path for the first entry that
  676.   matches the filename given by Path and the attributes given by Attr. The
  677.   result is returned in the search record given by SearchRec. The return
  678.   value is zero if the function was successful. Otherwise the return value
  679.   is a Windows error code. FindFirst is typically used in conjunction with
  680.   FindNext and FindClose as follows:
  681.  
  682.     Result := FindFirst(Path, Attr, SearchRec);
  683.     while Result = 0 do
  684.     begin
  685.       ProcessSearchRec(SearchRec);
  686.       Result := FindNext(SearchRec);
  687.     end;
  688.     FindClose(SearchRec);
  689.  
  690.   where ProcessSearchRec represents user-defined code that processes the
  691.   information in a search record. }
  692.  
  693. function FindFirst(const Path: string; Attr: Integer;
  694.   var F: TSearchRec): Integer;
  695.  
  696. { FindNext returs the next entry that matches the name and attributes
  697.   specified in a previous call to FindFirst. The search record must be one
  698.   that was passed to FindFirst. The return value is zero if the function was
  699.   successful. Otherwise the return value is a Windows error code. }
  700.  
  701. function FindNext(var F: TSearchRec): Integer;
  702.  
  703. { FindClose terminates a FindFirst/FindNext sequence. FindClose does nothing
  704.   in the 16-bit version of Windows, but is required in the 32-bit version,
  705.   so for maximum portability every FindFirst/FindNext sequence should end
  706.   with a call to FindClose. }
  707.  
  708. procedure FindClose(var F: TSearchRec);
  709.  
  710. { FileGetDate returns the DOS date-and-time stamp of the file given by
  711.   Handle. The return value is -1 if the handle is invalid. The
  712.   FileDateToDateTime function can be used to convert the returned value to
  713.   a TDateTime value. }
  714.  
  715. function FileGetDate(Handle: Integer): Integer;
  716.  
  717. { FileSetDate sets the DOS date-and-time stamp of the file given by Handle
  718.   to the value given by Age. The DateTimeToFileDate function can be used to
  719.   convert a TDateTime value to a DOS date-and-time stamp. The return value
  720.   is zero if the function was successful. Otherwise the return value is a
  721.   Windows error code. }
  722.  
  723. function FileSetDate(Handle: Integer; Age: Integer): Integer;
  724.  
  725. { FileGetAttr returns the file attributes of the file given by FileName. The
  726.   attributes can be examined by AND-ing with the faXXXX constants defined
  727.   above. A return value of -1 indicates that an error occurred. }
  728.  
  729. function FileGetAttr(const FileName: string): Integer;
  730.  
  731. { FileSetAttr sets the file attributes of the file given by FileName to the
  732.   value given by Attr. The attribute value is formed by OR-ing the
  733.   appropriate faXXXX constants. The return value is zero if the function was
  734.   successful. Otherwise the return value is a Windows error code. }
  735.  
  736. function FileSetAttr(const FileName: string; Attr: Integer): Integer;
  737.  
  738. { DeleteFile deletes the file given by FileName. The return value is True if
  739.   the file was successfully deleted, or False if an error occurred. }
  740.  
  741. function DeleteFile(const FileName: string): Boolean;
  742.  
  743. { RenameFile renames the file given by OldName to the name given by NewName.
  744.   The return value is True if the file was successfully renamed, or False if
  745.   an error occurred. }
  746.  
  747. function RenameFile(const OldName, NewName: string): Boolean;
  748.  
  749. { ChangeFileExt changes the extension of a filename. FileName specifies a
  750.   filename with or without an extension, and Extension specifies the new
  751.   extension for the filename. The new extension can be a an empty string or
  752.   a period followed by up to three characters. }
  753.  
  754. function ChangeFileExt(const FileName, Extension: string): string;
  755.  
  756. { ExtractFilePath extracts the drive and directory parts of the given
  757.   filename. The resulting string is the leftmost characters of FileName,
  758.   up to and including the colon or backslash that separates the path
  759.   information from the name and extension. The resulting string is empty
  760.   if FileName contains no drive and directory parts. }
  761.  
  762. function ExtractFilePath(const FileName: string): string;
  763.  
  764. { ExtractFileDir extracts the drive and directory parts of the given
  765.   filename. The resulting string is a directory name suitable for passing
  766.   to SetCurrentDir, CreateDir, etc. The resulting string is empty if
  767.   FileName contains no drive and directory parts. }
  768.  
  769. function ExtractFileDir(const FileName: string): string;
  770.  
  771. { ExtractFileDrive extracts the drive part of the given filename.  For
  772.   filenames with drive letters, the resulting string is '<drive>:'.
  773.   For filenames with a UNC path, the resulting string is in the form
  774.   '\\<servername>\<sharename>'.  If the given path contains neither
  775.   style of filename, the result is an empty string. }
  776.  
  777. function ExtractFileDrive(const FileName: string): string;
  778.  
  779. { ExtractFileName extracts the name and extension parts of the given
  780.   filename. The resulting string is the leftmost characters of FileName,
  781.   starting with the first character after the colon or backslash that
  782.   separates the path information from the name and extension. The resulting
  783.   string is equal to FileName if FileName contains no drive and directory
  784.   parts. }
  785.  
  786. function ExtractFileName(const FileName: string): string;
  787.  
  788. { ExtractFileExt extracts the extension part of the given filename. The
  789.   resulting string includes the period character that separates the name
  790.   and extension parts. The resulting string is empty if the given filename
  791.   has no extension. }
  792.  
  793. function ExtractFileExt(const FileName: string): string;
  794.  
  795. { ExpandFileName expands the given filename to a fully qualified filename.
  796.   The resulting string consists of a drive letter, a colon, a root relative
  797.   directory path, and a filename. Embedded '.' and '..' directory references
  798.   are removed. }
  799.  
  800. function ExpandFileName(const FileName: string): string;
  801.  
  802. { ExpandUNCFileName expands the given filename to a fully qualified filename.
  803.   This function is the same as ExpandFileName except that it will return the
  804.   drive portion of the filename in the format '\\<servername>\<sharename> if
  805.   that drive is actually a network resource instead of a local resource.
  806.   Like ExpandFileName, embedded '.' and '..' directory references are
  807.   removed. }
  808.  
  809. function ExpandUNCFileName(const FileName: string): string;
  810.  
  811. {  ExtractRelativePath will return a file path name relative to the given
  812.    BaseName.  It strips the common path dirs and adds '..\' for each level
  813.    up from the BaseName path. }
  814.  
  815. function ExtractRelativePath(const BaseName, DestName: string): string;
  816.  
  817. { FileSearch searches for the file given by Name in the list of directories
  818.   given by DirList. The directory paths in DirList must be separated by
  819.   semicolons. The search always starts with the current directory of the
  820.   current drive. The returned value is a concatenation of one of the
  821.   directory paths and the filename, or an empty string if the file could not
  822.   be located. }
  823.  
  824. function FileSearch(const Name, DirList: string): string;
  825.  
  826. { DiskFree returns the number of free bytes on the specified drive number,
  827.   where 0 = Current, 1 = A, 2 = B, etc. DiskFree returns -1 if the drive
  828.   number is invalid. }
  829.  
  830. function DiskFree(Drive: Byte): Integer;
  831.  
  832. { DiskSize returns the size in bytes of the specified drive number, where
  833.   0 = Current, 1 = A, 2 = B, etc. DiskSize returns -1 if the drive number
  834.   is invalid. }
  835.  
  836. function DiskSize(Drive: Byte): Integer;
  837.  
  838. { FileDateToDateTime converts a DOS date-and-time value to a TDateTime
  839.   value. The FileAge, FileGetDate, and FileSetDate routines operate on DOS
  840.   date-and-time values, and the Time field of a TSearchRec used by the
  841.   FindFirst and FindNext functions contains a DOS date-and-time value. }
  842.  
  843. function FileDateToDateTime(FileDate: Integer): TDateTime;
  844.  
  845. { DateTimeToFileDate converts a TDateTime value to a DOS date-and-time
  846.   value. The FileAge, FileGetDate, and FileSetDate routines operate on DOS
  847.   date-and-time values, and the Time field of a TSearchRec used by the
  848.   FindFirst and FindNext functions contains a DOS date-and-time value. }
  849.  
  850. function DateTimeToFileDate(DateTime: TDateTime): Integer;
  851.  
  852. { GetCurrentDir returns the current directory. }
  853.  
  854. function GetCurrentDir: string;
  855.  
  856. { SetCurrentDir sets the current directory. The return value is True if
  857.   the current directory was successfully changed, or False if an error
  858.   occurred. }
  859.  
  860. function SetCurrentDir(const Dir: string): Boolean;
  861.  
  862. { CreateDir creates a new directory. The return value is True if a new
  863.   directory was successfully created, or False if an error occurred. }
  864.  
  865. function CreateDir(const Dir: string): Boolean;
  866.  
  867. { RemoveDir deletes an existing empty directory. The return value is
  868.   True if the directory was successfully deleted, or False if an error
  869.   occurred. }
  870.  
  871. function RemoveDir(const Dir: string): Boolean;
  872.  
  873. { PChar routines }
  874.  
  875. { StrLen returns the number of characters in Str, not counting the null
  876.   terminator. }
  877.  
  878. function StrLen(Str: PChar): Cardinal;
  879.  
  880. { StrEnd returns a pointer to the null character that terminates Str. }
  881.  
  882. function StrEnd(Str: PChar): PChar;
  883.  
  884. { StrMove copies exactly Count characters from Source to Dest and returns
  885.   Dest. Source and Dest may overlap. }
  886.  
  887. function StrMove(Dest, Source: PChar; Count: Cardinal): PChar;
  888.  
  889. { StrCopy copies Source to Dest and returns Dest. }
  890.  
  891. function StrCopy(Dest, Source: PChar): PChar;
  892.  
  893. { StrECopy copies Source to Dest and returns StrEnd(Dest). }
  894.  
  895. function StrECopy(Dest, Source: PChar): PChar;
  896.  
  897. { StrLCopy copies at most MaxLen characters from Source to Dest and
  898.   returns Dest. }
  899.  
  900. function StrLCopy(Dest, Source: PChar; MaxLen: Cardinal): PChar;
  901.  
  902. { StrPCopy copies the Pascal style string Source into Dest and
  903.   returns Dest. }
  904.  
  905. function StrPCopy(Dest: PChar; const Source: string): PChar;
  906.  
  907. { StrPLCopy copies at most MaxLen characters from the Pascal style string
  908.   Source into Dest and returns Dest. }
  909.  
  910. function StrPLCopy(Dest: PChar; const Source: string;
  911.   MaxLen: Cardinal): PChar;
  912.  
  913. { StrCat appends a copy of Source to the end of Dest and returns Dest. }
  914.  
  915. function StrCat(Dest, Source: PChar): PChar;
  916.  
  917. { StrLCat appends at most MaxLen - StrLen(Dest) characters from Source to
  918.   the end of Dest, and returns Dest. }
  919.  
  920. function StrLCat(Dest, Source: PChar; MaxLen: Cardinal): PChar;
  921.  
  922. { StrComp compares Str1 to Str2. The return value is less than 0 if
  923.   Str1 < Str2, 0 if Str1 = Str2, or greater than 0 if Str1 > Str2. }
  924.  
  925. function StrComp(Str1, Str2: PChar): Integer;
  926.  
  927. { StrIComp compares Str1 to Str2, without case sensitivity. The return
  928.   value is the same as StrComp. }
  929.  
  930. function StrIComp(Str1, Str2: PChar): Integer;
  931.  
  932. { StrLComp compares Str1 to Str2, for a maximum length of MaxLen
  933.   characters. The return value is the same as StrComp. }
  934.  
  935. function StrLComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
  936.  
  937. { StrLIComp compares Str1 to Str2, for a maximum length of MaxLen
  938.   characters, without case sensitivity. The return value is the same
  939.   as StrComp. }
  940.  
  941. function StrLIComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
  942.  
  943. { StrScan returns a pointer to the first occurrence of Chr in Str. If Chr
  944.   does not occur in Str, StrScan returns NIL. The null terminator is
  945.   considered to be part of the string. }
  946.  
  947. function StrScan(Str: PChar; Chr: Char): PChar;
  948.  
  949. { StrRScan returns a pointer to the last occurrence of Chr in Str. If Chr
  950.   does not occur in Str, StrRScan returns NIL. The null terminator is
  951.   considered to be part of the string. }
  952.  
  953. function StrRScan(Str: PChar; Chr: Char): PChar;
  954.  
  955. { StrPos returns a pointer to the first occurrence of Str2 in Str1. If
  956.   Str2 does not occur in Str1, StrPos returns NIL. }
  957.  
  958. function StrPos(Str1, Str2: PChar): PChar;
  959.  
  960. { StrUpper converts Str to upper case and returns Str. }
  961.  
  962. function StrUpper(Str: PChar): PChar;
  963.  
  964. { StrLower converts Str to lower case and returns Str. }
  965.  
  966. function StrLower(Str: PChar): PChar;
  967.  
  968. { StrPas converts Str to a Pascal style string. This function is provided
  969.   for backwards compatibility only. To convert a null terminated string to
  970.   a Pascal style string, use a type cast or an assignment. }
  971.  
  972. function StrPas(Str: PChar): string;
  973.  
  974. { StrAlloc allocates a buffer of the given size on the heap. The size of
  975.   the allocated buffer is encoded in a four byte header that immediately
  976.   preceeds the buffer. To dispose the buffer, use StrDispose. }
  977.  
  978. function StrAlloc(Size: Cardinal): PChar;
  979.  
  980. { StrBufSize returns the allocated size of the given buffer, not including
  981.   the two byte header. }
  982.  
  983. function StrBufSize(Str: PChar): Cardinal;
  984.  
  985. { StrNew allocates a copy of Str on the heap. If Str is NIL, StrNew returns
  986.   NIL and doesn't allocate any heap space. Otherwise, StrNew makes a
  987.   duplicate of Str, obtaining space with a call to the StrAlloc function,
  988.   and returns a pointer to the duplicated string. To dispose the string,
  989.   use StrDispose. }
  990.  
  991. function StrNew(Str: PChar): PChar;
  992.  
  993. { StrDispose disposes a string that was previously allocated with StrAlloc
  994.   or StrNew. If Str is NIL, StrDispose does nothing. }
  995.  
  996. procedure StrDispose(Str: PChar);
  997.  
  998. { String formatting routines }
  999.  
  1000. { The Format routine formats the argument list given by the Args parameter
  1001.   using the format string given by the Format parameter.
  1002.  
  1003.   Format strings contain two types of objects--plain characters and format
  1004.   specifiers. Plain characters are copied verbatim to the resulting string.
  1005.   Format specifiers fetch arguments from the argument list and apply
  1006.   formatting to them.
  1007.  
  1008.   Format specifiers have the following form:
  1009.  
  1010.     "%" [index ":"] ["-"] [width] ["." prec] type
  1011.  
  1012.   A format specifier begins with a % character. After the % come the
  1013.   following, in this order:
  1014.  
  1015.   -  an optional argument index specifier, [index ":"]
  1016.   -  an optional left-justification indicator, ["-"]
  1017.   -  an optional width specifier, [width]
  1018.   -  an optional precision specifier, ["." prec]
  1019.   -  the conversion type character, type
  1020.  
  1021.   The following conversion characters are supported:
  1022.  
  1023.   d  Decimal. The argument must be an integer value. The value is converted
  1024.      to a string of decimal digits. If the format string contains a precision
  1025.      specifier, it indicates that the resulting string must contain at least
  1026.      the specified number of digits; if the value has less digits, the
  1027.      resulting string is left-padded with zeros.
  1028.  
  1029.   e  Scientific. The argument must be a floating-point value. The value is
  1030.      converted to a string of the form "-d.ddd...E+ddd". The resulting
  1031.      string starts with a minus sign if the number is negative, and one digit
  1032.      always precedes the decimal point. The total number of digits in the
  1033.      resulting string (including the one before the decimal point) is given
  1034.      by the precision specifer in the format string--a default precision of
  1035.      15 is assumed if no precision specifer is present. The "E" exponent
  1036.      character in the resulting string is always followed by a plus or minus
  1037.      sign and at least three digits.
  1038.  
  1039.   f  Fixed. The argument must be a floating-point value. The value is
  1040.      converted to a string of the form "-ddd.ddd...". The resulting string
  1041.      starts with a minus sign if the number is negative. The number of digits
  1042.      after the decimal point is given by the precision specifier in the
  1043.      format string--a default of 2 decimal digits is assumed if no precision
  1044.      specifier is present.
  1045.  
  1046.   g  General. The argument must be a floating-point value. The value is
  1047.      converted to the shortest possible decimal string using fixed or
  1048.      scientific format. The number of significant digits in the resulting
  1049.      string is given by the precision specifier in the format string--a
  1050.      default precision of 15 is assumed if no precision specifier is present.
  1051.      Trailing zeros are removed from the resulting string, and a decimal
  1052.      point appears only if necessary. The resulting string uses fixed point
  1053.      format if the number of digits to the left of the decimal point in the
  1054.      value is less than or equal to the specified precision, and if the
  1055.      value is greater than or equal to 0.00001. Otherwise the resulting
  1056.      string uses scientific format.
  1057.  
  1058.   n  Number. The argument must be a floating-point value. The value is
  1059.      converted to a string of the form "-d,ddd,ddd.ddd...". The "n" format
  1060.      corresponds to the "f" format, except that the resulting string
  1061.      contains thousand separators.
  1062.  
  1063.   m  Money. The argument must be a floating-point value. The value is
  1064.      converted to a string that represents a currency amount. The conversion
  1065.      is controlled by the CurrencyString, CurrencyFormat, NegCurrFormat,
  1066.      ThousandSeparator, DecimalSeparator, and CurrencyDecimals global
  1067.      variables, all of which are initialized from the Currency Format in
  1068.      the International section of the Windows Control Panel. If the format
  1069.      string contains a precision specifier, it overrides the value given
  1070.      by the CurrencyDecimals global variable.
  1071.  
  1072.   p  Pointer. The argument must be a pointer value. The value is converted
  1073.      to a string of the form "XXXX:YYYY" where XXXX and YYYY are the
  1074.      segment and offset parts of the pointer expressed as four hexadecimal
  1075.      digits.
  1076.  
  1077.   s  String. The argument must be a character, a string, or a PChar value.
  1078.      The string or character is inserted in place of the format specifier.
  1079.      The precision specifier, if present in the format string, specifies the
  1080.      maximum length of the resulting string. If the argument is a string
  1081.      that is longer than this maximum, the string is truncated.
  1082.  
  1083.   x  Hexadecimal. The argument must be an integer value. The value is
  1084.      converted to a string of hexadecimal digits. If the format string
  1085.      contains a precision specifier, it indicates that the resulting string
  1086.      must contain at least the specified number of digits; if the value has
  1087.      less digits, the resulting string is left-padded with zeros.
  1088.  
  1089.   Conversion characters may be specified in upper case as well as in lower
  1090.   case--both produce the same results.
  1091.  
  1092.   For all floating-point formats, the actual characters used as decimal and
  1093.   thousand separators are obtained from the DecimalSeparator and
  1094.   ThousandSeparator global variables.
  1095.  
  1096.   Index, width, and precision specifiers can be specified directly using
  1097.   decimal digit string (for example "%10d"), or indirectly using an asterisk
  1098.   charcater (for example "%*.*f"). When using an asterisk, the next argument
  1099.   in the argument list (which must be an integer value) becomes the value
  1100.   that is actually used. For example "Format('%*.*f', [8, 2, 123.456])" is
  1101.   the same as "Format('%8.2f', [123.456])".
  1102.  
  1103.   A width specifier sets the minimum field width for a conversion. If the
  1104.   resulting string is shorter than the minimum field width, it is padded
  1105.   with blanks to increase the field width. The default is to right-justify
  1106.   the result by adding blanks in front of the value, but if the format
  1107.   specifier contains a left-justification indicator (a "-" character
  1108.   preceding the width specifier), the result is left-justified by adding
  1109.   blanks after the value.
  1110.  
  1111.   An index specifier sets the current argument list index to the specified
  1112.   value. The index of the first argument in the argument list is 0. Using
  1113.   index specifiers, it is possible to format the same argument multiple
  1114.   times. For example "Format('%d %d %0:d %d', [10, 20])" produces the string
  1115.   '10 20 10 20'.
  1116.  
  1117.   The Format function can be combined with other formatting functions. For
  1118.   example
  1119.  
  1120.     S := Format('Your total was %s on %s', [
  1121.       FormatFloat('$#,##0.00;;zero', Total),
  1122.       FormatDateTime('mm/dd/yy', Date)]);
  1123.  
  1124.   which uses the FormatFloat and FormatDateTime functions to customize the
  1125.   format beyond what is possible with Format. }
  1126.  
  1127. function Format(const Format: string; const Args: array of const): string;
  1128.  
  1129. { FmtStr formats the argument list given by Args using the format string
  1130.   given by Format into the string variable given by Result. For further
  1131.   details, see the description of the Format function. }
  1132.  
  1133. procedure FmtStr(var Result: string; const Format: string;
  1134.   const Args: array of const);
  1135.  
  1136. { StrFmt formats the argument list given by Args using the format string
  1137.   given by Format into the buffer given by Buffer. It is up to the caller to
  1138.   ensure that Buffer is large enough for the resulting string. The returned
  1139.   value is Buffer. For further details, see the description of the Format
  1140.   function. }
  1141.  
  1142. function StrFmt(Buffer, Format: PChar; const Args: array of const): PChar;
  1143.  
  1144. { StrFmt formats the argument list given by Args using the format string
  1145.   given by Format into the buffer given by Buffer. The resulting string will
  1146.   contain no more than MaxLen characters, not including the null terminator.
  1147.   The returned value is Buffer. For further details, see the description of
  1148.   the Format function. }
  1149.  
  1150. function StrLFmt(Buffer: PChar; MaxLen: Cardinal; Format: PChar;
  1151.   const Args: array of const): PChar;
  1152.  
  1153. { FormatBuf formats the argument list given by Args using the format string
  1154.   given by Format and FmtLen into the buffer given by Buffer and BufLen.
  1155.   The Format parameter is a reference to a buffer containing FmtLen
  1156.   characters, and the Buffer parameter is a reference to a buffer of BufLen
  1157.   characters. The returned value is the number of characters actually stored
  1158.   in Buffer. The returned value is always less than or equal to BufLen. For
  1159.   further details, see the description of the Format function. }
  1160.  
  1161. function FormatBuf(var Buffer; BufLen: Cardinal; const Format;
  1162.   FmtLen: Cardinal; const Args: array of const): Cardinal;
  1163.  
  1164. { Floating point conversion routines }
  1165.  
  1166. { FloatToStr converts the floating-point value given by Value to its string
  1167.   representation. The conversion uses general number format with 15
  1168.   significant digits. For further details, see the description of the
  1169.   FloatToStrF function. }
  1170.  
  1171. function FloatToStr(Value: Extended): string;
  1172.  
  1173. { CurrToStr converts the currency value given by Value to its string
  1174.   representation. The conversion uses general number format. For further
  1175.   details, see the description of the CurrToStrF function. }
  1176.  
  1177. function CurrToStr(Value: Currency): string;
  1178.  
  1179. { FloatToStrF converts the floating-point value given by Value to its string
  1180.   representation. The Format parameter controls the format of the resulting
  1181.   string. The Precision parameter specifies the precision of the given value.
  1182.   It should be 7 or less for values of type Single, 15 or less for values of
  1183.   type Double, and 18 or less for values of type Extended. The meaning of the
  1184.   Digits parameter depends on the particular format selected.
  1185.  
  1186.   The possible values of the Format parameter, and the meaning of each, are
  1187.   described below.
  1188.  
  1189.   ffGeneral - General number format. The value is converted to the shortest
  1190.   possible decimal string using fixed or scientific format. Trailing zeros
  1191.   are removed from the resulting string, and a decimal point appears only
  1192.   if necessary. The resulting string uses fixed point format if the number
  1193.   of digits to the left of the decimal point in the value is less than or
  1194.   equal to the specified precision, and if the value is greater than or
  1195.   equal to 0.00001. Otherwise the resulting string uses scientific format,
  1196.   and the Digits parameter specifies the minimum number of digits in the
  1197.   exponent (between 0 and 4).
  1198.  
  1199.   ffExponent - Scientific format. The value is converted to a string of the
  1200.   form "-d.ddd...E+dddd". The resulting string starts with a minus sign if
  1201.   the number is negative, and one digit always precedes the decimal point.
  1202.   The total number of digits in the resulting string (including the one
  1203.   before the decimal point) is given by the Precision parameter. The "E"
  1204.   exponent character in the resulting string is always followed by a plus
  1205.   or minus sign and up to four digits. The Digits parameter specifies the
  1206.   minimum number of digits in the exponent (between 0 and 4).
  1207.  
  1208.   ffFixed - Fixed point format. The value is converted to a string of the
  1209.   form "-ddd.ddd...". The resulting string starts with a minus sign if the
  1210.   number is negative, and at least one digit always precedes the decimal
  1211.   point. The number of digits after the decimal point is given by the Digits
  1212.   parameter--it must be between 0 and 18. If the number of digits to the
  1213.   left of the decimal point is greater than the specified precision, the
  1214.   resulting value will use scientific format.
  1215.  
  1216.   ffNumber - Number format. The value is converted to a string of the form
  1217.   "-d,ddd,ddd.ddd...". The ffNumber format corresponds to the ffFixed format,
  1218.   except that the resulting string contains thousand separators.
  1219.  
  1220.   ffCurrency - Currency format. The value is converted to a string that
  1221.   represents a currency amount. The conversion is controlled by the
  1222.   CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, and
  1223.   DecimalSeparator global variables, all of which are initialized from the
  1224.   Currency Format in the International section of the Windows Control Panel.
  1225.   The number of digits after the decimal point is given by the Digits
  1226.   parameter--it must be between 0 and 18.
  1227.  
  1228.   For all formats, the actual characters used as decimal and thousand
  1229.   separators are obtained from the DecimalSeparator and ThousandSeparator
  1230.   global variables.
  1231.  
  1232.   If the given value is a NAN (not-a-number), the resulting string is 'NAN'.
  1233.   If the given value is positive infinity, the resulting string is 'INF'. If
  1234.   the given value is negative infinity, the resulting string is '-INF'. }
  1235.  
  1236. function FloatToStrF(Value: Extended; Format: TFloatFormat;
  1237.   Precision, Digits: Integer): string;
  1238.  
  1239. { CurrToStrF converts the currency value given by Value to its string
  1240.   representation. A call to CurrToStrF corresponds to a call to
  1241.   FloatToStrF with an implied precision of 19 digits. }
  1242.  
  1243. function CurrToStrF(Value: Currency; Format: TFloatFormat;
  1244.   Digits: Integer): string;
  1245.  
  1246. { FloatToText converts the given floating-point value to its decimal
  1247.   representation using the specified format, precision, and digits. The
  1248.   Value parameter must be a variable of type Extended or Currency, as
  1249.   indicated by the ValueType parameter. The resulting string of characters
  1250.   is stored in the given buffer, and the returned value is the number of
  1251.   characters stored. The resulting string is not null-terminated. For
  1252.   further details, see the description of the FloatToStrF function. }
  1253.  
  1254. function FloatToText(Buffer: PChar; const Value; ValueType: TFloatValue;
  1255.   Format: TFloatFormat; Precision, Digits: Integer): Integer;
  1256.  
  1257. { FormatFloat formats the floating-point value given by Value using the
  1258.   format string given by Format. The following format specifiers are
  1259.   supported in the format string:
  1260.  
  1261.   0     Digit placeholder. If the value being formatted has a digit in the
  1262.         position where the '0' appears in the format string, then that digit
  1263.         is copied to the output string. Otherwise, a '0' is stored in that
  1264.         position in the output string.
  1265.  
  1266.   #     Digit placeholder. If the value being formatted has a digit in the
  1267.         position where the '#' appears in the format string, then that digit
  1268.         is copied to the output string. Otherwise, nothing is stored in that
  1269.         position in the output string.
  1270.  
  1271.   .     Decimal point. The first '.' character in the format string
  1272.         determines the location of the decimal separator in the formatted
  1273.         value; any additional '.' characters are ignored. The actual
  1274.         character used as a the decimal separator in the output string is
  1275.         determined by the DecimalSeparator global variable. The default value
  1276.         of DecimalSeparator is specified in the Number Format of the
  1277.         International section in the Windows Control Panel.
  1278.  
  1279.   ,     Thousand separator. If the format string contains one or more ','
  1280.         characters, the output will have thousand separators inserted between
  1281.         each group of three digits to the left of the decimal point. The
  1282.         placement and number of ',' characters in the format string does not
  1283.         affect the output, except to indicate that thousand separators are
  1284.         wanted. The actual character used as a the thousand separator in the
  1285.         output is determined by the ThousandSeparator global variable. The
  1286.         default value of ThousandSeparator is specified in the Number Format
  1287.         of the International section in the Windows Control Panel.
  1288.  
  1289.   E+    Scientific notation. If any of the strings 'E+', 'E-', 'e+', or 'e-'
  1290.   E-    are contained in the format string, the number is formatted using
  1291.   e+    scientific notation. A group of up to four '0' characters can
  1292.   e-    immediately follow the 'E+', 'E-', 'e+', or 'e-' to determine the
  1293.         minimum number of digits in the exponent. The 'E+' and 'e+' formats
  1294.         cause a plus sign to be output for positive exponents and a minus
  1295.         sign to be output for negative exponents. The 'E-' and 'e-' formats
  1296.         output a sign character only for negative exponents.
  1297.  
  1298.   'xx'  Characters enclosed in single or double quotes are output as-is, and
  1299.   "xx"  do not affect formatting.
  1300.  
  1301.   ;     Separates sections for positive, negative, and zero numbers in the
  1302.         format string.
  1303.  
  1304.   The locations of the leftmost '0' before the decimal point in the format
  1305.   string and the rightmost '0' after the decimal point in the format string
  1306.   determine the range of digits that are always present in the output string.
  1307.  
  1308.   The number being formatted is always rounded to as many decimal places as
  1309.   there are digit placeholders ('0' or '#') to the right of the decimal
  1310.   point. If the format string contains no decimal point, the value being
  1311.   formatted is rounded to the nearest whole number.
  1312.  
  1313.   If the number being formatted has more digits to the left of the decimal
  1314.   separator than there are digit placeholders to the left of the '.'
  1315.   character in the format string, the extra digits are output before the
  1316.   first digit placeholder.
  1317.  
  1318.   To allow different formats for positive, negative, and zero values, the
  1319.   format string can contain between one and three sections separated by
  1320.   semicolons.
  1321.  
  1322.   One section - The format string applies to all values.
  1323.  
  1324.   Two sections - The first section applies to positive values and zeros, and
  1325.   the second section applies to negative values.
  1326.  
  1327.   Three sections - The first section applies to positive values, the second
  1328.   applies to negative values, and the third applies to zeros.
  1329.  
  1330.   If the section for negative values or the section for zero values is empty,
  1331.   that is if there is nothing between the semicolons that delimit the
  1332.   section, the section for positive values is used instead.
  1333.  
  1334.   If the section for positive values is empty, or if the entire format string
  1335.   is empty, the value is formatted using general floating-point formatting
  1336.   with 15 significant digits, corresponding to a call to FloatToStrF with
  1337.   the ffGeneral format. General floating-point formatting is also used if
  1338.   the value has more than 18 digits to the left of the decimal point and
  1339.   the format string does not specify scientific notation.
  1340.  
  1341.   The table below shows some sample formats and the results produced when
  1342.   the formats are applied to different values:
  1343.  
  1344.   Format string          1234        -1234       0.5         0
  1345.   -----------------------------------------------------------------------
  1346.                          1234        -1234       0.5         0
  1347.   0                      1234        -1234       1           0
  1348.   0.00                   1234.00     -1234.00    0.50        0.00
  1349.   #.##                   1234        -1234       .5
  1350.   #,##0.00               1,234.00    -1,234.00   0.50        0.00
  1351.   #,##0.00;(#,##0.00)    1,234.00    (1,234.00)  0.50        0.00
  1352.   #,##0.00;;Zero         1,234.00    -1,234.00   0.50        Zero
  1353.   0.000E+00              1.234E+03   -1.234E+03  5.000E-01   0.000E+00
  1354.   #.###E-0               1.234E3     -1.234E3    5E-1        0E0
  1355.   ----------------------------------------------------------------------- }
  1356.  
  1357. function FormatFloat(const Format: string; Value: Extended): string;
  1358.  
  1359. { FormatCurr formats the currency value given by Value using the format
  1360.   string given by Format. For further details, see the description of the
  1361.   FormatFloat function. }
  1362.  
  1363. function FormatCurr(const Format: string; Value: Currency): string;
  1364.  
  1365. { FloatToTextFmt converts the given floating-point value to its decimal
  1366.   representation using the specified format. The Value parameter must be a
  1367.   variable of type Extended or Currency, as indicated by the ValueType
  1368.   parameter. The resulting string of characters is stored in the given
  1369.   buffer, and the returned value is the number of characters stored. The
  1370.   resulting string is not null-terminated. For further details, see the
  1371.   description of the FormatFloat function. }
  1372.  
  1373. function FloatToTextFmt(Buffer: PChar; const Value; ValueType: TFloatValue;
  1374.   Format: PChar): Integer;
  1375.  
  1376. { StrToFloat converts the given string to a floating-point value. The string
  1377.   must consist of an optional sign (+ or -), a string of digits with an
  1378.   optional decimal point, and an optional 'E' or 'e' followed by a signed
  1379.   integer. Leading and trailing blanks in the string are ignored. The
  1380.   DecimalSeparator global variable defines the character that must be used
  1381.   as a decimal point. Thousand separators and currency symbols are not
  1382.   allowed in the string. If the string doesn't contain a valid value, an
  1383.   EConvertError exception is raised. }
  1384.  
  1385. function StrToFloat(const S: string): Extended;
  1386.  
  1387. { StrToCurr converts the given string to a currency value. For further
  1388.   details, see the description of the StrToFloat function. }
  1389.  
  1390. function StrToCurr(const S: string): Currency;
  1391.  
  1392. { TextToFloat converts the null-terminated string given by Buffer to a
  1393.   floating-point value which is returned in the variable given by Value.
  1394.   The Value parameter must be a variable of type Extended or Currency, as
  1395.   indicated by the ValueType parameter. The return value is True if the
  1396.   conversion was successful, or False if the string is not a valid
  1397.   floating-point value. For further details, see the description of the
  1398.   StrToFloat function. }
  1399.  
  1400. function TextToFloat(Buffer: PChar; var Value;
  1401.   ValueType: TFloatValue): Boolean;
  1402.  
  1403. { FloatToDecimal converts a floating-point value to a decimal representation
  1404.   that is suited for further formatting. The Value parameter must be a
  1405.   variable of type Extended or Currency, as indicated by the ValueType
  1406.   parameter. For values of type Extended, the Precision parameter specifies
  1407.   the requested number of significant digits in the result--the allowed range
  1408.   is 1..18. For values of type Currency, the Precision parameter is ignored,
  1409.   and the implied precision of the conversion is 19 digits. The Decimals
  1410.   parameter specifies the requested maximum number of digits to the left of
  1411.   the decimal point in the result. Precision and Decimals together control
  1412.   how the result is rounded. To produce a result that always has a given
  1413.   number of significant digits regardless of the magnitude of the number,
  1414.   specify 9999 for the Decimals parameter. The result of the conversion is
  1415.   stored in the specified TFloatRec record as follows:
  1416.  
  1417.   Exponent - Contains the magnitude of the number, i.e. the number of
  1418.   significant digits to the right of the decimal point. The Exponent field
  1419.   is negative if the absolute value of the number is less than one. If the
  1420.   number is a NAN (not-a-number), Exponent is set to -32768. If the number
  1421.   is INF or -INF (positive or negative infinity), Exponent is set to 32767.
  1422.  
  1423.   Negative - True if the number is negative, False if the number is zero
  1424.   or positive.
  1425.  
  1426.   Digits - Contains up to 18 (for type Extended) or 19 (for type Currency)
  1427.   significant digits followed by a null terminator. The implied decimal
  1428.   point (if any) is not stored in Digits. Trailing zeros are removed, and
  1429.   if the resulting number is zero, NAN, or INF, Digits contains nothing but
  1430.   the null terminator. }
  1431.  
  1432. procedure FloatToDecimal(var Result: TFloatRec; const Value;
  1433.   ValueType: TFloatValue; Precision, Decimals: Integer);
  1434.  
  1435. { Date/time support routines }
  1436.  
  1437. function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
  1438.  
  1439. function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
  1440. function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
  1441. function TimeStampToMSecs(const TimeStamp: TTimeStamp): Comp;
  1442.  
  1443. { EncodeDate encodes the given year, month, and day into a TDateTime value.
  1444.   The year must be between 1 and 9999, the month must be between 1 and 12,
  1445.   and the day must be between 1 and N, where N is the number of days in the
  1446.   specified month. If the specified values are not within range, an
  1447.   EConvertError exception is raised. The resulting value is the number of
  1448.   days between 12/30/1899 and the given date. }
  1449.  
  1450. function EncodeDate(Year, Month, Day: Word): TDateTime;
  1451.  
  1452. { EncodeTime encodes the given hour, minute, second, and millisecond into a
  1453.   TDateTime value. The hour must be between 0 and 23, the minute must be
  1454.   between 0 and 59, the second must be between 0 and 59, and the millisecond
  1455.   must be between 0 and 999. If the specified values are not within range, an
  1456.   EConvertError exception is raised. The resulting value is a number between
  1457.   0 (inclusive) and 1 (not inclusive) that indicates the fractional part of
  1458.   a day given by the specified time. The value 0 corresponds to midnight,
  1459.   0.5 corresponds to noon, 0.75 corresponds to 6:00 pm, etc. }
  1460.  
  1461. function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;
  1462.  
  1463. { DecodeDate decodes the integral (date) part of the given TDateTime value
  1464.   into its corresponding year, month, and day. If the given TDateTime value
  1465.   is less than or equal to zero, the year, month, and day return parameters
  1466.   are all set to zero. }
  1467.  
  1468. procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);
  1469.  
  1470. { DecodeTime decodes the fractional (time) part of the given TDateTime value
  1471.   into its corresponding hour, minute, second, and millisecond. }
  1472.  
  1473. procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word);
  1474.  
  1475. { DateTimeToSystemTime converts a date and time from Delphi's TDateTime
  1476.   format into the Win32 API's TSystemTime format. }
  1477.  
  1478. procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
  1479.  
  1480. { SystemTimeToDateTime converts a date and time from the Win32 API's
  1481.   TSystemTime format into Delphi's TDateTime format. }
  1482.  
  1483. function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
  1484.  
  1485. { DayOfWeek returns the day of the week of the given date. The result is an
  1486.   integer between 1 and 7, corresponding to Sunday through Saturday. }
  1487.  
  1488. function DayOfWeek(Date: TDateTime): Integer;
  1489.  
  1490. { Date returns the current date. }
  1491.  
  1492. function Date: TDateTime;
  1493.  
  1494. { Time returns the current time. }
  1495.  
  1496. function Time: TDateTime;
  1497.  
  1498. { Now returns the current date and time, corresponding to Date + Time. }
  1499.  
  1500. function Now: TDateTime;
  1501.  
  1502. { IncMonth returns Date shifted by the specified number of months.
  1503.   NumberOfMonths parameter can be negative, to return a date N months ago.
  1504.   If the input day of month is greater than the last day of the resulting
  1505.   month, the day is set to the last day of the resulting month.
  1506.   Input time of day is copied to the DateTime result.  }
  1507.  
  1508. function IncMonth(const Date: TDateTime; NumberOfMonths: Integer): TDateTime;
  1509.  
  1510. { IsLeapYear determines whether the given year is a leap year. }
  1511.  
  1512. function IsLeapYear(Year: Word): Boolean;
  1513.  
  1514. type
  1515.   PDayTable = ^TDayTable;
  1516.   TDayTable = array[1..12] of Word;
  1517.  
  1518. { The MonthDays array can be used to quickly find the number of
  1519.   days in a month:  MonthDays[IsLeapYear(Y), M]      }
  1520.  
  1521. const
  1522.   MonthDays: array [Boolean] of TDayTable =
  1523.     ((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
  1524.      (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));
  1525.  
  1526. { DateToStr converts the date part of the given TDateTime value to a string.
  1527.   The conversion uses the format specified by the ShortDateFormat global
  1528.   variable. }
  1529.  
  1530. function DateToStr(Date: TDateTime): string;
  1531.  
  1532. { TimeToStr converts the time part of the given TDateTime value to a string.
  1533.   The conversion uses the format specified by the LongTimeFormat global
  1534.   variable. }
  1535.  
  1536. function TimeToStr(Time: TDateTime): string;
  1537.  
  1538. { DateTimeToStr converts the given date and time to a string. The resulting
  1539.   string consists of a date and time formatted using the ShortDateFormat and
  1540.   LongTimeFormat global variables. Time information is included in the
  1541.   resulting string only if the fractional part of the given date and time
  1542.   value is non-zero. }
  1543.  
  1544. function DateTimeToStr(DateTime: TDateTime): string;
  1545.  
  1546. { StrToDate converts the given string to a date value. The string must
  1547.   consist of two or three numbers, separated by the character defined by
  1548.   the DateSeparator global variable. The order for month, day, and year is
  1549.   determined by the ShortDateFormat global variable--possible combinations
  1550.   are m/d/y, d/m/y, and y/m/d. If the string contains only two numbers, it
  1551.   is interpreted as a date (m/d or d/m) in the current year. Year values
  1552.   between 0 and 99 are assumed to be in the current century. If the given
  1553.   string does not contain a valid date, an EConvertError exception is
  1554.   raised. }
  1555.  
  1556. function StrToDate(const S: string): TDateTime;
  1557.  
  1558. { StrToTime converts the given string to a time value. The string must
  1559.   consist of two or three numbers, separated by the character defined by
  1560.   the TimeSeparator global variable, optionally followed by an AM or PM
  1561.   indicator. The numbers represent hour, minute, and (optionally) second,
  1562.   in that order. If the time is followed by AM or PM, it is assumed to be
  1563.   in 12-hour clock format. If no AM or PM indicator is included, the time
  1564.   is assumed to be in 24-hour clock format. If the given string does not
  1565.   contain a valid time, an EConvertError exception is raised. }
  1566.  
  1567. function StrToTime(const S: string): TDateTime;
  1568.  
  1569. { StrToDateTime converts the given string to a date and time value. The
  1570.   string must contain a date optionally followed by a time. The date and
  1571.   time parts of the string must follow the formats described for the
  1572.   StrToDate and StrToTime functions. }
  1573.  
  1574. function StrToDateTime(const S: string): TDateTime;
  1575.  
  1576. { FormatDateTime formats the date-and-time value given by DateTime using the
  1577.   format given by Format. The following format specifiers are supported:
  1578.  
  1579.   c       Displays the date using the format given by the ShortDateFormat
  1580.           global variable, followed by the time using the format given by
  1581.           the LongTimeFormat global variable. The time is not displayed if
  1582.           the fractional part of the DateTime value is zero.
  1583.  
  1584.   d       Displays the day as a number without a leading zero (1-31).
  1585.  
  1586.   dd      Displays the day as a number with a leading zero (01-31).
  1587.  
  1588.   ddd     Displays the day as an abbreviation (Sun-Sat) using the strings
  1589.           given by the ShortDayNames global variable.
  1590.  
  1591.   dddd    Displays the day as a full name (Sunday-Saturday) using the strings
  1592.           given by the LongDayNames global variable.
  1593.  
  1594.   ddddd   Displays the date using the format given by the ShortDateFormat
  1595.           global variable.
  1596.  
  1597.   dddddd  Displays the date using the format given by the LongDateFormat
  1598.           global variable.
  1599.  
  1600.   g       Displays the period/era as an abbreviation (Japanese and
  1601.           Taiwanese locales only).
  1602.  
  1603.   gg      Displays the period/era as a full name.
  1604.  
  1605.   e       Displays the year in the current period/era as a number without
  1606.           a leading zero (Japanese, Korean and Taiwanese locales only).
  1607.  
  1608.   ee      Displays the year in the current period/era as a number with
  1609.           a leading zero (Japanese, Korean and Taiwanese locales only).
  1610.  
  1611.   m       Displays the month as a number without a leading zero (1-12). If
  1612.           the m specifier immediately follows an h or hh specifier, the
  1613.           minute rather than the month is displayed.
  1614.  
  1615.   mm      Displays the month as a number with a leading zero (01-12). If
  1616.           the mm specifier immediately follows an h or hh specifier, the
  1617.           minute rather than the month is displayed.
  1618.  
  1619.   mmm     Displays the month as an abbreviation (Jan-Dec) using the strings
  1620.           given by the ShortMonthNames global variable.
  1621.  
  1622.   mmmm    Displays the month as a full name (January-December) using the
  1623.           strings given by the LongMonthNames global variable.
  1624.  
  1625.   yy      Displays the year as a two-digit number (00-99).
  1626.  
  1627.   yyyy    Displays the year as a four-digit number (0000-9999).
  1628.  
  1629.   h       Displays the hour without a leading zero (0-23).
  1630.  
  1631.   hh      Displays the hour with a leading zero (00-23).
  1632.  
  1633.   n       Displays the minute without a leading zero (0-59).
  1634.  
  1635.   nn      Displays the minute with a leading zero (00-59).
  1636.  
  1637.   s       Displays the second without a leading zero (0-59).
  1638.  
  1639.   ss      Displays the second with a leading zero (00-59).
  1640.  
  1641.   t       Displays the time using the format given by the ShortTimeFormat
  1642.           global variable.
  1643.  
  1644.   tt      Displays the time using the format given by the LongTimeFormat
  1645.           global variable.
  1646.  
  1647.   am/pm   Uses the 12-hour clock for the preceding h or hh specifier, and
  1648.           displays 'am' for any hour before noon, and 'pm' for any hour
  1649.           after noon. The am/pm specifier can use lower, upper, or mixed
  1650.           case, and the result is displayed accordingly.
  1651.  
  1652.   a/p     Uses the 12-hour clock for the preceding h or hh specifier, and
  1653.           displays 'a' for any hour before noon, and 'p' for any hour after
  1654.           noon. The a/p specifier can use lower, upper, or mixed case, and
  1655.           the result is displayed accordingly.
  1656.  
  1657.   ampm    Uses the 12-hour clock for the preceding h or hh specifier, and
  1658.           displays the contents of the TimeAMString global variable for any
  1659.           hour before noon, and the contents of the TimePMString global
  1660.           variable for any hour after noon.
  1661.  
  1662.   /       Displays the date separator character given by the DateSeparator
  1663.           global variable.
  1664.  
  1665.   :       Displays the time separator character given by the TimeSeparator
  1666.           global variable.
  1667.  
  1668.   'xx'    Characters enclosed in single or double quotes are displayed as-is,
  1669.   "xx"    and do not affect formatting.
  1670.  
  1671.   Format specifiers may be written in upper case as well as in lower case
  1672.   letters--both produce the same result.
  1673.  
  1674.   If the string given by the Format parameter is empty, the date and time
  1675.   value is formatted as if a 'c' format specifier had been given.
  1676.  
  1677.   The following example:
  1678.  
  1679.     S := FormatDateTime('"The meeting is on" dddd, mmmm d, yyyy, ' +
  1680.       '"at" hh:mm AM/PM', StrToDateTime('2/15/95 10:30am'));
  1681.  
  1682.   assigns 'The meeting is on Wednesday, February 15, 1995 at 10:30 AM' to
  1683.   the string variable S. }
  1684.  
  1685. function FormatDateTime(const Format: string; DateTime: TDateTime): string;
  1686.  
  1687. { DateTimeToString converts the date and time value given by DateTime using
  1688.   the format string given by Format into the string variable given by Result.
  1689.   For further details, see the description of the FormatDateTime function. }
  1690.  
  1691. procedure DateTimeToString(var Result: string; const Format: string;
  1692.   DateTime: TDateTime);
  1693.  
  1694. { System error messages }
  1695.  
  1696. function SysErrorMessage(ErrorCode: Integer): string;
  1697.  
  1698. { Initialization file support }
  1699.  
  1700. function GetLocaleStr(Locale, LocaleType: Integer; const Default: string): string;
  1701. function GetLocaleChar(Locale, LocaleType: Integer; Default: Char): Char;
  1702.  
  1703. { GetFormatSettings resets all date and number format variables to their
  1704.   default values. }
  1705.  
  1706. procedure GetFormatSettings;
  1707.  
  1708. { Exception handling routines }
  1709.  
  1710. function ExceptObject: TObject;
  1711. function ExceptAddr: Pointer;
  1712.  
  1713. function ExceptionErrorMessage(ExceptObject: TObject; ExceptAddr: Pointer;
  1714.   Buffer: PChar; Size: Integer): Integer;
  1715.  
  1716. procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
  1717.  
  1718. procedure Abort;
  1719.  
  1720. procedure OutOfMemoryError;
  1721.  
  1722. procedure Beep;
  1723.  
  1724. { MBCS functions }
  1725.  
  1726. { LeadBytes is a char set that indicates which char values are lead bytes
  1727.   in multibyte character sets (Japanese, Chinese, etc).
  1728.   This set is always empty for western locales. }
  1729. var
  1730.   LeadBytes: set of Char = [];
  1731.  
  1732. { ByteType indicates what kind of byte exists at the Index'th byte in S.
  1733.   Western locales always return mbSingleByte.  Far East multibyte locales
  1734.   may also return mbLeadByte, indicating the byte is the first in a multibyte
  1735.   character sequence, and mbTrailByte, indicating that the byte is the second
  1736.   in a multibyte character sequence.  Parameters are assumed to be valid. }
  1737.  
  1738. function ByteType(const S: string; Index: Integer): TMbcsByteType;
  1739.  
  1740. { StrByteType works the same as ByteType, but on null-terminated PChar strings }
  1741.  
  1742. function StrByteType(Str: PChar; Index: Cardinal): TMbcsByteType;
  1743.  
  1744. { ByteToCharLen returns the character length of a MBCS string, scanning the
  1745.   string for up to MaxLen bytes.  In multibyte character sets, the number of
  1746.   characters in a string may be less than the number of bytes.  }
  1747.  
  1748. function ByteToCharLen(const S: string; MaxLen: Integer): Integer;
  1749.  
  1750. { CharToByteLen returns the byte length of a MBCS string, scanning the string
  1751.   for up to MaxLen characters. }
  1752.  
  1753. function CharToByteLen(const S: string; MaxLen: Integer): Integer;
  1754.  
  1755. { ByteToCharIndex returns the 1-based character index of the Index'th byte in
  1756.   a MBCS string.  Returns zero if Index is out of range:
  1757.   (Index <= 0) or (Index > Length(S)) }
  1758.  
  1759. function ByteToCharIndex(const S: string; Index: Integer): Integer;
  1760.  
  1761. { CharToByteIndex returns the 1-based byte index of the Index'th character
  1762.   in a MBCS string.  Returns zero if Index or Result are out of range:
  1763.   (Index <= 0) or (Index > Length(S)) or (Result would be > Length(S)) }
  1764.  
  1765. function CharToByteIndex(const S: string; Index: Integer): Integer;
  1766.  
  1767. { IsPathDelimiter returns True if the character at byte S[Index]
  1768.   is '\', and it is not a MBCS lead or trail byte. }
  1769.  
  1770. function IsPathDelimiter(const S: string; Index: Integer): Boolean;
  1771.  
  1772. { IsDelimiter returns True if the character at byte S[Index] matches any
  1773.   character in the Delimiters string, and the character is not a MBCS lead or
  1774.   trail byte.  S may contain multibyte characters; Delimiters must contain
  1775.   only single byte characters. }
  1776.  
  1777. function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
  1778.  
  1779. { LastDelimiter returns the byte index in S of the rightmost whole
  1780.   character that matches any character in Delimiters (except null (#0)).
  1781.   S may contain multibyte characters; Delimiters must contain only single
  1782.   byte non-null characters.
  1783.   Example: LastDelimiter('\.:', 'c:\filename.ext') returns 12. }
  1784.  
  1785. function LastDelimiter(const Delimiters, S: string): Integer;
  1786.  
  1787. { AnsiCompareFileName supports DOS file name comparison idiosyncracies
  1788.   in Far East locales (Zenkaku).  In non-MBCS locales, AnsiCompareFileName
  1789.   is identical to AnsiCompareText.  For general purpose file name comparisions,
  1790.   you should use this function instead of AnsiCompareText. }
  1791.  
  1792. function AnsiCompareFileName(const S1, S2: string): Integer;
  1793.  
  1794. { AnsiLowerCaseFileName supports lowercase conversion idiosyncracies of
  1795.   DOS file names in Far East locales (Zenkaku).  In non-MBCS locales,
  1796.   AnsiLowerCaseFileName is identical to AnsiLowerCase. }
  1797.  
  1798. function AnsiLowerCaseFileName(const S: string): string;
  1799.  
  1800. { AnsiUpperCaseFileName supports uppercase conversion idiosyncracies of
  1801.   DOS file names in Far East locales (Zenkaku).  In non-MBCS locales,
  1802.   AnsiUpperCaseFileName is identical to AnsiUpperCase. }
  1803.  
  1804. function AnsiUpperCaseFileName(const S: string): string;
  1805.  
  1806. { AnsiPos:  Same as Pos but supports MBCS strings }
  1807.  
  1808. function AnsiPos(const Substr, S: string): Integer;
  1809.  
  1810. { AnsiStrPos: Same as StrPos but supports MBCS strings }
  1811.  
  1812. function AnsiStrPos(Str, SubStr: PChar): PChar;
  1813.  
  1814. { AnsiStrRScan: Same as StrRScan but supports MBCS strings }
  1815.  
  1816. function AnsiStrRScan(Str: PChar; Chr: Char): PChar;
  1817.  
  1818. { AnsiStrScan: Same as StrScan but supports MBCS strings }
  1819.  
  1820. function AnsiStrScan(Str: PChar; Chr: Char): PChar;
  1821.  
  1822. { Package support routines }
  1823.  
  1824. { Package Info flags }
  1825.  
  1826. const
  1827.   pfNeverBuild = $00000001;
  1828.   pfDesignOnly = $00000002;
  1829.   pfRunOnly = $00000004;
  1830.   pfModuleTypeMask = $C0000000;
  1831.   pfExeModule = $00000000;
  1832.   pfPackageModule = $40000000;
  1833.   pfLibraryModule = $80000000;
  1834.  
  1835. { Unit info flags }
  1836.  
  1837. const
  1838.   ufMainUnit = $01;
  1839.   ufPackageUnit = $02;
  1840.   ufWeakUnit = $04;
  1841.   ufOrgWeakUnit = $08;
  1842.   ufImplicitUnit = $10;
  1843.  
  1844.   ufWeakPackageUnit = ufPackageUnit or ufWeakUnit;
  1845.  
  1846. { Procedure type of the callback given to GetPackageInfo.  Name is the actual
  1847.   name of the package element.  If IsUnit is True then Name is the name of
  1848.   a contained unit; a required package if False.  Param is the value passed
  1849.   to GetPackageInfo }
  1850.  
  1851. type
  1852.   TNameType = (ntContainsUnit, ntRequiresPackage);
  1853.  
  1854.   TPackageInfoProc = procedure (const Name: string; NameType: TNameType; Flags: Byte; Param: Pointer);
  1855.  
  1856. { LoadPackage loads a given package DLL, checks for duplicate units and
  1857.   calls the initialization blocks of all the contained units }
  1858.  
  1859. function LoadPackage(const Name: string): HMODULE;
  1860.  
  1861. { UnloadPackage does the opposite of LoadPackage by calling the finalization
  1862.   blocks of all contained units, then unloading the package DLL }
  1863.  
  1864. procedure UnloadPackage(Module: HMODULE);
  1865.  
  1866. { GetPackageInfo accesses the given package's info table and enumerates
  1867.   all the contained units and required packages }
  1868.  
  1869. procedure GetPackageInfo(Module: HMODULE; Param: Pointer; var Flags: Integer;
  1870.   InfoProc: TPackageInfoProc);
  1871.  
  1872. { GetPackageDescription loads the description resource from the package
  1873.   library. If the description resource does not exist,
  1874.   an empty string is returned. }
  1875. function GetPackageDescription(ModuleName: PChar): string;
  1876.  
  1877. { InitializePackage Validates and initializes the given package DLL }
  1878.  
  1879. procedure InitializePackage(Module: HMODULE);
  1880.  
  1881. { FinalizePackage finalizes the given package DLL }
  1882.  
  1883. procedure FinalizePackage(Module: HMODULE);
  1884.  
  1885. { RaiseLastWin32Error calls the GetLastError API to retrieve the code for }
  1886. { the last occuring Win32 error.  If GetLastError returns an error code,  }
  1887. { RaiseLastWin32Error then raises an exception with the error code and    }
  1888. { message associated with with error. }
  1889.  
  1890. procedure RaiseLastWin32Error;
  1891.  
  1892. { Win32Check is used to check the return value of a Win32 API function     }
  1893. { which returns a BOOL to indicate success.  If the Win32 API function     }
  1894. { returns False (indicating failure), Win32Check calls RaiseLastWin32Error }
  1895. { to raise an exception.  If the Win32 API function returns True,          }
  1896. { Win32Check returns True. }
  1897.  
  1898. function Win32Check(RetVal: BOOL): BOOL;
  1899.  
  1900. { Termination procedure support }
  1901.  
  1902. type
  1903.   TTerminateProc = function: Boolean;
  1904.  
  1905. { Call AddTerminateProc to add a terminate procedure to the system list of }
  1906. { termination procedures.  Delphi will call all of the function in the     }
  1907. { termination procedure list before an application terminates.  The user-  }
  1908. { defined TermProc function should return True if the application can      }
  1909. { safely terminate or False if the application cannot safely terminate.    }
  1910. { If one of the functions in the termination procedure list returns False, }
  1911. { the application will not terminate. }
  1912.  
  1913. procedure AddTerminateProc(TermProc: TTerminateProc);
  1914.  
  1915. { CallTerminateProcs is called by VCL when an application is about to }
  1916. { terminate.  It returns True only if all of the functions in the     }
  1917. { system's terminate procedure list return True.  This function is    }
  1918. { intended only to be called by Delphi, and it should not be called   }
  1919. { directly. }
  1920.  
  1921. function CallTerminateProcs: Boolean;
  1922.  
  1923. function GDAL: Longint;
  1924. procedure RCS;
  1925. procedure RPR;
  1926.  
  1927. {$I SYSUTILS.INC}
  1928.  
  1929. implementation
  1930.